{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二次练习\n",
    "\n",
    "+ 请**务必**交到**exer2**文件夹下，谢绝交到master下\n",
    "+ 请**不要改动**任何文件，拜托\n",
    "+ 请在10月16日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 食物和热量\n",
    "\n",
    "已知，以下食物每100g的千卡路里如下：\n",
    "\n",
    "小米粥 45  \n",
    "粗粮馒头 223  \n",
    "全麦面包 235  \n",
    "瘦猪肉 143  \n",
    "鸡翅 194  \n",
    "培根 181  \n",
    "火腿肠 212 \n",
    "\n",
    "建立一个空的字典，把上述键值对依此添加进去。 \n",
    "通过循环形式，显示，如“我吃了二两”+“小米粥”，“增加了”+“45”千卡路里。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我吃了二两小米粥，增加了45千卡路里。\n",
      "\n",
      "我吃了二两粗粮馒头，增加了223千卡路里。\n",
      "\n",
      "我吃了二两全麦面包，增加了235千卡路里。\n",
      "\n",
      "我吃了二两瘦猪肉，增加了143千卡路里。\n",
      "\n",
      "我吃了二两鸡翅，增加了194千卡路里。\n",
      "\n",
      "我吃了二两培根，增加了181千卡路里。\n",
      "\n",
      "我吃了二两火腿肠，增加了212千卡路里。\n",
      "\n"
     ]
    }
   ],
   "source": [
    "aliment_calorie={}\n",
    "aliment_calorie['小米粥'] ='45'\n",
    "aliment_calorie['粗粮馒头'] ='223'\n",
    "aliment_calorie['全麦面包'] ='235'\n",
    "aliment_calorie['瘦猪肉'] ='143'\n",
    "aliment_calorie['鸡翅'] ='194'\n",
    "aliment_calorie['培根'] ='181'\n",
    "aliment_calorie['火腿肠'] ='212'\n",
    "for word, meaning in aliment_calorie.items():\n",
    "    print(\"我吃了二两%s，\" % word,end=\"\")\n",
    "    print(\"增加了%s千卡路里。\\n\" % meaning)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 运动和消耗\n",
    "常见三种运动的消耗热量表：  \n",
    "慢走 (一小时4公里) 255 卡  \n",
    "慢跑 (一小时9公里) 655 卡  \n",
    "羽毛球（一小时） 440 卡  \n",
    "\n",
    "模仿课件3-dict_set中的cell[9]做个刷题，直到答对而且答完为止。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "（一小时4公里）255卡\n",
      "\n",
      "emmmm,你觉得吧，这是个啥运动🌚🌚🌚？\n",
      "慢走  慢跑  羽毛球  你以为我想理你吗🙄  \n",
      "- 慢跑\n",
      "不对哎👀！再猜一下🙈？\n",
      "\n",
      "emmmm,你觉得吧，这是个啥运动🌚🌚🌚？\n",
      "慢走  慢跑  羽毛球  你以为我想理你吗🙄  \n",
      "- 慢走\n",
      "答对了耶🎉🎉\n",
      "\n",
      " (一小时9公里) 655 卡\n",
      "\n",
      "emmmm,你觉得吧，这是个啥运动🌚🌚🌚？\n",
      "慢走  慢跑  羽毛球  你以为我想理你吗🙄  \n",
      "- 慢跑\n",
      "答对了耶🎉🎉\n",
      "\n",
      "（一小时） 440 卡\n",
      "\n",
      "emmmm,你觉得吧，这是个啥运动🌚🌚🌚？\n",
      "慢走  慢跑  羽毛球  你以为我想理你吗🙄  \n",
      "- 羽毛球\n",
      "答对了耶🎉🎉\n",
      "\n",
      "真的编不出来了，哭唧唧🤢\n",
      "\n",
      "emmmm,你觉得吧，这是个啥运动🌚🌚🌚？\n",
      "慢走  慢跑  羽毛球  你以为我想理你吗🙄  \n",
      "- 你以为我想理你吗🙄\n",
      "答对了耶🎉🎉\n"
     ]
    }
   ],
   "source": [
    "sport_calories =  {'慢走': '（一小时4公里）255卡',\n",
    "                '慢跑': ' (一小时9公里) 655 卡',\n",
    "                '羽毛球': '（一小时） 440 卡',\n",
    "                '你以为我想理你吗🙄':'真的编不出来了，哭唧唧🤢'\n",
    "                }\n",
    "\n",
    "def show_words(sport_calories):\n",
    "    display_message = \"\"\n",
    "    for word in sport_calories.keys():\n",
    "        display_message += word + '  '\n",
    "    print(display_message)\n",
    "    \n",
    "for meaning in sport_calories.values():\n",
    "    print(\"\\n%s\" % meaning)\n",
    "\n",
    "    correct = False\n",
    "    while not correct:\n",
    "        \n",
    "        print(\"\\nemmmm,你觉得吧，这是个啥运动🌚🌚🌚？\")\n",
    "        show_words(sport_calories)\n",
    "        guessed_word = input(\"- \")    \n",
    "        \n",
    "        if sport_calories[guessed_word] == meaning:\n",
    "            print(\"答对了耶🎉🎉\")\n",
    "            correct = True\n",
    "        else:\n",
    "            print(\"不对哎👀！再猜一下🙈？\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dictionary: A collection of key-value pairs.\n",
      "Function: A named set of instructions that defines a set of actions in Python.\n",
      "List: A collection of values that are not connected, but have an order.\n"
     ]
    }
   ],
   "source": [
    "# 对dict来说，输出时不按任何顺序\n",
    "# 可以通过sorted()函数使结果有序输出\n",
    "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n",
    "                'dictionary': 'A collection of key-value pairs.',\n",
    "                'function': 'A named set of instructions that defines a set of actions in Python.',\n",
    "                }\n",
    "\n",
    "for word in sorted(python_words.keys()):\n",
    "    print(\"%s: %s\" % (word.title(), python_words[word]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 江西最高山\n",
    "\n",
    "[江西最高的十座山]{http://jx.ifeng.com/a/20160628/4693979_0.shtml}\n",
    "\n",
    "请模仿上例，创建包含山名和海拔的dict，并按如下形式循环输出：  \n",
    "“黄岗山海拔2157.8米”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "九岭头海拔1794米\n",
      "五虎岗海拔1891米\n",
      "军峰山海拔1760.9米\n",
      "南风面海拔2120.4米\n",
      "武功山金顶(白鹤峰)海拔1918.3米\n",
      "独竖尖海拔2128米\n",
      "玉京峰海拔1819.9米\n",
      "过风坳海拔1887米\n",
      "黄岗山海拔2157.8米\n",
      "齐云山海拔2061.3米\n"
     ]
    }
   ],
   "source": [
    "mountains_altitude = {'军峰山': '海拔1760.9米',\n",
    "                '九岭头': '海拔1794米',\n",
    "                '玉京峰': '海拔1819.9米',\n",
    "                '过风坳': '海拔1887米',\n",
    "                '五虎岗': '海拔1891米',\n",
    "                '武功山金顶(白鹤峰)': '海拔1918.3米',\n",
    "                '齐云山': '海拔2061.3米',\n",
    "                '南风面': '海拔2120.4米',\n",
    "                '独竖尖': '海拔2128米',\n",
    "                '黄岗山': '海拔2157.8米',\n",
    "                }\n",
    "\n",
    "for mountain in sorted(mountains_altitude.keys()):\n",
    "    print(\"%s%s\" % (mountain.title(), mountains_altitude[mountain]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 为室友打一波广告\n",
    "请参照课件3-dict_set中的cell[15]“卖室友”吧。  \n",
    "第一层dict的key可自选，如身高、爱好、技能等等。\n",
    "并以以下形式循环输出：  \n",
    "我知道的XXX，TA:  \n",
    "身高：160  \n",
    "爱好：吸猫  \n",
    "技能：python  \n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "其实吧，我和她们真的不熟🌚🌚，毕竟人家是个小仙女，出于塑料室友情，勉为其难介绍一下:自贡冷吃兔-张馨予\n",
      "身高: 也许和刘国梁差不多🙄🙄\n",
      "爱好: 不动，坚决不动\n",
      "技能: 发射爱心光波biu～❤️❤️\n",
      "\n",
      "其实吧，我和她们真的不熟🌚🌚，毕竟人家是个小仙女，出于塑料室友情，勉为其难介绍一下:柳州臭酸笋-易立怡\n",
      "身高: 似乎是个谜，主要取决于增高垫的高度👀👀\n",
      "爱好: 唱歌🎤，最近歌技下降很多啊\n",
      "技能: 宿舍中修眉小能手，修过的都说好\n",
      "\n",
      "其实吧，我和她们真的不熟🌚🌚，毕竟人家是个小仙女，出于塑料室友情，勉为其难介绍一下:赣州大脐橙-肖丽雯\n",
      "身高: 仅次于我，宿舍中为数不多身高正常的🙈🙈\n",
      "爱好: 唱歌，但似乎有点跑调？？\n",
      "技能: 待点亮\n"
     ]
    }
   ],
   "source": [
    "roommates = {'自贡冷吃兔-张馨予': {'身高': '也许和刘国梁差不多🙄🙄', '爱好': '不动，坚决不动', '技能':'发射爱心光波biu～❤️❤️'},\n",
    "        '柳州臭酸笋-易立怡': {'身高': '似乎是个谜，主要取决于增高垫的高度👀👀', '爱好': '唱歌🎤，最近歌技下降很多啊', '技能':'宿舍中修眉小能手，修过的都说好'},\n",
    "        '赣州大脐橙-肖丽雯': {'身高': '仅次于我，宿舍中为数不多身高正常的🙈🙈', '爱好': '唱歌，但似乎有点跑调？？', '技能':'待点亮'},\n",
    "        }\n",
    "\n",
    "\n",
    "for roommates_name, roommates_information in roommates.items():\n",
    "    print(\"\\n其实吧，我和她们真的不熟🌚🌚，毕竟人家是个小仙女，出于塑料室友情，勉为其难介绍一下:%s\" % roommates_name.title())\n",
    "    print(\"身高: \" + roommates_information['身高'])\n",
    "    print(\"爱好: \" + roommates_information['爱好'])\n",
    "    print(\"技能: \" + roommates_information['技能'])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
